package cn.tedu.scalacollection

import scala.collection.mutable
import scala.collection.mutable._

/**
 * @author Amos
 * @date 2022/5/17
 */

object CollectionTest {
  def main(args: Array[String]): Unit = {
    // 一. 不可变集合
    // 1. 数组的声明
    val arr = new Array[Int](4)
    arr(0) = 11
    arr(1) = 12
    arr(2) = 13
    arr(3) = 14

    println(arr.toList)

    val arr1 = Array(1, 2, 3, 4, 5)
    println(arr1.toList)

    // 2. 不可变List
    val list = List(1, 2, 3, 4, 5)
    //    list.+:(6) // 在新的列表中添加元素

    println(list)
    val list1 = Nil // scala中表示空的List

    val list2 = 3 :: 2 :: 1 :: Nil
    println(list2)

    // 3. 不可变的Set
    val set = Set(1, 1, 1, 3, 4, 5, 5, 5, 6, 6)
    println(set)

    // 4. 不可变的Map
    val map = Map("a" -> 1, "b" -> 2, "c" -> 3)
    println(map)

    // 二、可变集合
    // 1.可变的ArrayBuffer
    val abf1 = new ArrayBuffer[Int]()
    val abf2 = ArrayBuffer(1, 2, 3, 4, 5)
    abf2.+=(6, 7, 8, 9)
    println(abf2)

    // 2. 可变的ListBuffer
    val listbuffer = new ListBuffer[Int]()
    val listbuffer1 = ListBuffer(1, 2, 3, 4)
    listbuffer1.+=(5, 6, 7, 8, 9, 10)
    println(listbuffer1)

    // 3.可变的Set
    val set1 = mutable.Set(1, 2, 3, 4)
    set1.+=(4, 5, 6, 4, 4, 4)
    println(set1)

    // 4. 可变的Map
    val map1 = mutable.Map("a" -> 1, "b" -> 2, "c" -> 3, ("f",5))
    map1.+=("d"->4)
    println(map1)

  }

}
